package com.acwing.partition44;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/5/22 21:45
 */
public class AC4367拍照2 {

    private static final int N = 100010;
    private static int[] a = new int[N], b = new int[N];
    private static boolean[] st = new boolean[N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 1; i <= n; i++) a[i] = nextInt();
        for (int i = 1; i <= n; i++) b[i] = nextInt();
        int ans = 0;
        for (int i = n, j = n; i > 0 && j > 0; i--, j--) {
            while (st[b[j]]) j--;
            while (a[i] != b[j]) {
                ans++;
                st[a[i]] = true;
                i--;
            }
        }
        writer.println(ans);
        writer.flush();
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
